package cn.edu.hncst.controller;

import cn.edu.hncst.dao.UserDao;
import cn.edu.hncst.dao.impl.UserDaoImpl;
import cn.edu.hncst.entity.User;
import cn.edu.hncst.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取用户id
        String id = req.getParameter("id");
        UserDao userDao = new UserDaoImpl();
        //根据id进行查找
        User user = userDao.queryById(Integer.valueOf(id));
        //将查找到的数据进行存储
        req.setAttribute("user",user);
        //带着数据进入修改页面
        req.getRequestDispatcher("/update.jsp").forward(req,resp);

    }
}
